package 晚间作业0421

import 晚间作业0421.Scala_04_01.PercentCalculation.double2PercentCalculator
import 晚间作业0421.Scala_04_02.Factorial.factorial

import scala.language.{implicitConversions, postfixOps}


/**
 * 课后作业1
 */
object Scala_04_01 {
  def main(args: Array[String]): Unit = {
    println(120.0 +% 10)
  }

  class PercentCalculation(var x: Double) {
    def +%(percent: Double): Double = x.toDouble * percent / 100 + x
  }

  object PercentCalculation {
    implicit def double2PercentCalculator(x: Double): PercentCalculation = new PercentCalculation(x)
  }
}

/**
 * 课后作业2
 */
object Scala_04_02 {
  def main(args: Array[String]): Unit = {
    println(5!)
  }

  class Factorial (var x: Int) {
    val ! : Int = {
      var tmp = 1
      for(i <- 1 to x) tmp *= i
      tmp
    }
  }

  object Factorial {
    implicit def factorial(x: Int): Factorial = new Factorial(x)
  }
}



